package com.kin207.netty.udp;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelProgressivePromise;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.channel.socket.DatagramPacket;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import io.netty.util.CharsetUtil;

public class UdpChannel implements Channel {
	public ChannelHandlerContext channelHandlerContext;
	public SocketAddress socketAddress;

	public UdpChannel(ChannelHandlerContext channelHandlerContext, SocketAddress socketAddress) {
		super();
		this.channelHandlerContext = channelHandlerContext;
		this.socketAddress = socketAddress;
	}
	
	public UdpChannel(ChannelHandlerContext channelHandlerContext) {
		super();
		this.channelHandlerContext = channelHandlerContext;
	}

	public <T> Attribute<T> attr(AttributeKey<T> key) {
		// TODO Auto-generated method stub
		return null;
	}

	public <T> boolean hasAttr(AttributeKey<T> key) {
		// TODO Auto-generated method stub
		return false;
	}

	public ChannelFuture bind(SocketAddress localAddress) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture connect(SocketAddress remoteAddress) {
		this.socketAddress = remoteAddress;
		return null;
	}

	public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture disconnect() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture close() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture deregister() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture disconnect(ChannelPromise promise) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture close(ChannelPromise promise) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture deregister(ChannelPromise promise) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture write(Object msg) {
		return write(msg, null);
	}

	public ChannelFuture write(Object msg, ChannelPromise promise) {
		ChannelFuture channelFuture = null;
		if(msg!=null){
			channelFuture = channelHandlerContext.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(msg.toString(), CharsetUtil.UTF_8), (InetSocketAddress) socketAddress));
		}
		return channelFuture;
	}

	public ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) {
		ChannelFuture channelFuture = write(msg, promise);
		this.flush();
		return channelFuture;
	}

	public ChannelFuture writeAndFlush(Object msg) {
		ChannelFuture channelFuture = writeAndFlush(msg, null);
		return channelFuture;
	}

	public ChannelPromise newPromise() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelProgressivePromise newProgressivePromise() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture newSucceededFuture() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelFuture newFailedFuture(Throwable cause) {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelPromise voidPromise() {
		// TODO Auto-generated method stub
		return null;
	}

	public int compareTo(Channel o) {
		// TODO Auto-generated method stub
		return 0;
	}

	public ChannelId id() {
		// TODO Auto-generated method stub
		return null;
	}

	public EventLoop eventLoop() {
		// TODO Auto-generated method stub
		return null;
	}

	public Channel parent() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelConfig config() {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isOpen() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isRegistered() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isActive() {
		// TODO Auto-generated method stub
		return false;
	}

	public ChannelMetadata metadata() {
		// TODO Auto-generated method stub
		return null;
	}

	public SocketAddress localAddress() {
		// TODO Auto-generated method stub
		return null;
	}

	public SocketAddress remoteAddress() {
		return this.socketAddress;
	}

	public ChannelFuture closeFuture() {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean isWritable() {
		// TODO Auto-generated method stub
		return false;
	}

	public long bytesBeforeUnwritable() {
		// TODO Auto-generated method stub
		return 0;
	}

	public long bytesBeforeWritable() {
		// TODO Auto-generated method stub
		return 0;
	}

	public Unsafe unsafe() {
		// TODO Auto-generated method stub
		return null;
	}

	public ChannelPipeline pipeline() {
		// TODO Auto-generated method stub
		return null;
	}

	public ByteBufAllocator alloc() {
		// TODO Auto-generated method stub
		return null;
	}

	public Channel read() {
		// TODO Auto-generated method stub
		return null;
	}

	public Channel flush() {
		return this;
	}

	public ChannelHandlerContext getChannelHandlerContext() {
		return channelHandlerContext;
	}

	public void setChannelHandlerContext(ChannelHandlerContext channelHandlerContext) {
		this.channelHandlerContext = channelHandlerContext;
	}

	public SocketAddress getSocketAddress() {
		return socketAddress;
	}

	public void setSocketAddress(SocketAddress socketAddress) {
		this.socketAddress = socketAddress;
	}
	
}
